'''
Created on 2011-11-14

@author: Administrator
'''
from setting import *
import urllib2
import os

from stockdatadownload import *
import datetime
from foxtrader import *
from sinastock import *
from ibstock import *
from bloombergstock import *

def updateFoxUSstockdata():
#    regdict={'NS':'nyse'}
    regdict={'AS':'amex','NQ':'nasdaq','NS':'nyse'}
    ibdata=IBStock()
    fd=FoxTrader()
    sdd=StockDataDownload()  
#    stocklist={}
    for reg in regdict.keys():
        stocklist={}
        stocklist[reg]=ibdata.getstocklist(regdict[reg])    
        print reg,'get stock list update OK',reg,starttime,(datetime.datetime.now()-starttime).seconds    
        sdd.downloadstart(stocklist)
        print reg,'raw content download OK' ,starttime,(datetime.datetime.now()-starttime).seconds
        fd.startwork(stocklist)
        print reg,'foxtrader reg update OK',reg,starttime,(datetime.datetime.now()-starttime).seconds   
        fd.backup(reg)
        print reg,'foxtrader reg backup OK',reg,starttime,(datetime.datetime.now()-starttime).seconds  
if __name__ == '__main__':
    starttime=datetime.datetime.now()
    print 'start',starttime          
#    updateFoxAHstockdata()
#    print 'today AH work OK',starttime,(datetime.datetime.now()-starttime).seconds
    updateFoxUSstockdata()
    print 'today US work OK',starttime,(datetime.datetime.now()-starttime).seconds
